<template>
<div class="addressItemDivAll">
  <div class="addressItem" v-for="(item,index) in addressItemList" :key="index">
    <div class="addressItemDiv">
      <div class="reciverDiv">
        <div class="reciverName">收货人：<span>{{item.name}}</span></div>
        <div class="reciverPhone">{{item.phone}}</div>
      </div>
      <div class="reciverAddressDiv" @click="toAddress">
        <p class="reciverAddress">收货地址：<span>
        {{item.provinceName}}{{item.cityName}}{{item.districtName}}
        {{item.street}}
        </span></p>
      </div>
    </div>
    <div class="toolsDiv">
      <div class="checkbox" @click="setDefault(item,item.isDefault)">
        <span>
          <img v-if="item.isDefault" src="/static/images/pay/checkbox-active.png">
          <img v-else src="/static/images/pay/checkbox.png">
        </span>
        <label>设为默认</label>
      </div>
      <div class="editor" @click="editAddress(item)">
        <div class="editorImg"><img src="/static/images/pay/editor.png"></div>
        <p>编辑</p>
      </div>
      <div class="delete" @click="deleteAddress(item.id,item)">
        <div class="deleteImg"><img src="/static/images/pay/delete.png"></div>
        <p>删除</p>
      </div>
    </div>
  </div>
</div>
</template>

<script>
  export default {
    props:{
      addressItemList:{
        type: Object
      }
    },
    methods:{
      setDefault(item,isDefault) { //设置默认
        this.$http.get(`address/${item.id}/setDefault`).then((data)=>{ //默认
          this.$store.dispatch('setCurrentAddress', item) 
          this.$store.dispatch('defaultAddress', item.id) 
        })
        // let type = wx.getStorageSync('type')
        // if('normal' == type){ //闪购
        //   wx.navigateBack();   //返回上一个页面
        // }else if('share' == type){ //分享购
        //   wx.navigateBack();   //返回上一个页面
        // }
          wx.navigateBack();   //返回上一个页面
      },
      editAddress(item) {
        this.$store.dispatch('editAddress', item)
        const url = "../add-address/main";
        wx.navigateTo({ url })
      },
      deleteAddress(id,item) {
        this.$http.delete(`address/${id}`).then((data)=>{ //这里初始化地址列表
          this.$store.dispatch('deleteAddress', item)
        })
      }
    }
  }
</script>

<style scoped>
.addressItem{
  padding: 0 24rpx;
  background: #fff;
  margin-bottom: 25rpx;
}
.addressItem .addressItemDiv{
  height: 204rpx; 
}
.addressItem .addressItemDiv .reciverDiv{
  font-size: 28rpx;
  color: #2a2a2a;
  display: flex;
  height: 68rpx;
  align-items: center;
}
.addressItem .addressItemDiv .reciverDiv .reciverName{
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin-right: 10rpx;
}
.addressItem .addressItemDiv .reciverAddressDiv{
  display: flex;
  align-items: center;
  margin-top: 5rpx;
}
.addressItem .addressItemDiv .reciverAddressDiv .reciverAddress{
  font-size: 30rpx;
  color: #9e9e9e;
  line-height: 45rpx;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  flex: 1;
}
.addressItem .addressItemDiv .reciverAddressDiv .reciverRighticon{
  width: 17rpx;
  height: 30rpx;
}
.addressItem .addressItemDiv .reciverAddressDiv .reciverRighticon img{
  width: 100%;
  height: 100%;
  display: block;
}
.toolsDiv{
  border-top: 1rpx solid #efeff4;
  padding: 0 24rpx;
  height: 92rpx;
  display: flex;
  align-items: center;
}
.toolsDiv .checkbox {
  flex: 1;
  display: flex;
  align-items: center;
}
.toolsDiv .checkbox span{
  display: block;
  width: 44rpx;
  height: 44rpx;
  margin-right: 18rpx;
}
.toolsDiv .checkbox img{
  width: 100%;
  height: 100%;
  display: block;
}
.toolsDiv .checkbox label{
  font-size: 28rpx;
  color: #2a2a2a;  
}
.toolsDiv .editor{
  display: flex;
  align-items: center;
}
.toolsDiv .editor .editorImg{
  width: 32rpx;
  height: 32rpx;
}
.toolsDiv .editor .editorImg img{
  width: 100%;
  height: 100%;
  display: block;
}
.toolsDiv .editor p{
  font-size: 28rpx;
  color: #2a2a2a;
  margin-left: 18rpx;
}
.toolsDiv .delete{
  display: flex;
  align-items: center;
  margin-left: 20rpx;
}
.toolsDiv .delete .deleteImg{
  width: 32rpx;
  height: 32rpx;
}
.toolsDiv .delete .deleteImg img{
  width: 100%;
  height: 100%;
  display: block;
}
.toolsDiv .delete p{
  font-size: 28rpx;
  color: #2a2a2a;
  margin-left: 18rpx;
}
</style>
